<template>

    <div id="check-type" class="w-h-100 pos-r flex-1 apply-container page-public-s" style="box-sizing: border-box;overflow:hidden;">
        <div class="w-h-100 ver-flex pos-a" style="box-sizing: border-box; padding: 6px;">
            <div style="box-sizing: border-box;">
                <el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
                    <el-form class="box-f" ref="queryForm" :inline="true">
                        <el-form-item :label="$t('b0t63v7bGsmbXkQdwW4Q0')">
                            <el-select 
                                v-model="searchVal" 
                                filterable 
                                class="m-2" 
                                :placeholder="$t('g6AmUBb2H8qwj8DuC0TH')" 
                                @change="searchChange"
                            >
                                <el-option
                                    v-for="item in searchOptions"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                        <el-form-item>
                            <!-- 人员名称 -->
                            <template v-if="searchVal === '1'">
                                <el-select 
                                    v-model="transferVal" 
                                    filterable 
                                    class="m-2" 
                                    :placeholder="$t('k2Uv9N3Trufj48Sfbq8Ts')" 
                                    @change="acquireChange"
                                    value-key="id"
                                >
                                    <el-option
                                        v-for="item in projectNam"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    />
                                </el-select>
                            </template>
                            <!-- 人员编号 -->
                            <template v-else-if="searchVal === '2'">
                                <el-select 
                                    v-model="transferVal" 
                                    filterable 
                                    class="m-2" 
                                    :placeholder="$t('vu8QCtd2iRBgRQjHltpUu')" 
                                    @change="acquireChange"
                                    value-key="id"
                                >
                                    <el-option
                                        v-for="item in responsiblePle"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    />
                                </el-select>
                            </template>
                            <!-- 工种名称 -->
                            <template v-else-if="searchVal === '3'">
                                <el-select 
                                    v-model="transferVal" 
                                    filterable 
                                    class="m-2" 
                                    :placeholder="$t('hQmmlRmkje2IkDoxRZjj')" 
                                    @change="acquireChange"
                                    value-key="id"
                                >
                                    <el-option
                                        v-for="item in recordPle"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    />
                                </el-select>
                            </template>
                            <!-- 人员类型 -->
                            <template v-else-if="searchVal === '4'">
                                <el-select 
                                    v-model="transferVal" 
                                    filterable 
                                    class="m-2" 
                                    :placeholder="$t('cJWTh3T27ke_4LpTw0Tr')" 
                                    @change="acquireChange"
                                    value-key="id"
                                >
                                    <el-option
                                        v-for="item in typePle"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    />
                                </el-select>
                            </template>
                            <!-- 发证机关 -->
                            <template v-else-if="searchVal === '5'">
                                <el-select 
                                    v-model="transferVal" 
                                    filterable 
                                    class="m-2" 
                                    :placeholder="$t('2yZtTmqrjIhTp6Xopiew')" 
                                    @change="acquireChange"
                                    value-key="id"
                                >
                                    <el-option
                                        v-for="item in certificatePle"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    />
                                </el-select>
                            </template>
                            <!-- 是否启用 -->
                            <template v-else>
                                <el-select 
                                    v-model="transferVal" 
                                    filterable 
                                    class="m-2" 
                                    :placeholder="$t('4qSllUxIkPaA8Rqf3Jg8y')" 
                                    @change="acquireChange"
                                    value-key="id"
                                >
                                    <el-option
                                        v-for="item in enableStatus"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    />
                                </el-select>
                            </template>
                        </el-form-item>
                        <el-form-item >
                            <el-button @click='searchClick' type="primary" icon="ele-Search"> {{ $t('a4Uw6qeAZpctNhl3u7Uge') }} </el-button>
                            <el-button @click="resetClick" icon="ele-Refresh"> {{ $t('rxCkXeM2sO75ltcf8JyVj') }} </el-button>
                            <el-button @click="nodeClick('')" icon="ele-Plus" type="primary"> {{ $t('kfR7oKqGr0sNpRoAhHcM') }} </el-button>
                        </el-form-item>
                    </el-form>
                </el-card>
            </div>

            <div style="box-sizing: border-box;" class="flex-1 pos-r">
                <div class="pos-a w-h-100" style="box-sizing: border-box;">
                    <el-card class="box-card w-h-100" shadow="hover" style="margin-top: 8px;">
                        <div style="" class="w-h-100 ver-flex">
                            <div class="flex-1 pos-r">
                                <div class="pos-a w-h-100">

                                    <el-table :data="list" class="w-h-100" style="width: 100%" border v-loading="loading" element-loading-background="rgba(0, 0, 0, 0.5)">
                                        
                                        <el-table-column type="index" :label="$t('3eKEs1bExAXarYpdJemp')" width="55" align="center" :index="indexMethod" />
                                        
                                        <el-table-column prop="V_Name" :label="$t('lkwZAwlt9O46Ce47upGmZ')"  align="center" />
                                        
                                        <el-table-column prop="V_StateValue" :label="$t('sfwbsExMM3lGjDuN5zHf')" align="center" />
                                        
                                        <el-table-column prop="V_Remake" :label="$t('9RLaVEiJf1Z1Qv15o6Kll')" align="center" />

                                        
                                        <el-table-column :label="$t('liBmO8wb58NMw5HLu9Nf')" align="center" >
                                            <template #default="scope">
                                                <el-button @click="nodeClick(scope.row)" class="icon-e" icon="ele-Edit" size="small" text type="primary"> {{ $t('ucC9qxHvkvdh9OGEo1pn') }} </el-button>
                                                <el-popconfirm
                                                    confirm-button-text="确认"
                                                    cancel-button-text="取消"
                                                    icon="InfoFilled"
                                                    icon-color="#626AEF"
                                                    title=""
                                                    @confirm="deleteHandle(scope.row.N_Id , getData)"
                                                >
                                                    <template #reference>
                                                        <el-button class="icon-e" icon="ele-Delete" size="small" text type="danger"> {{ $t('mkwlMbm3qr88f0XxV9Pje') }} </el-button>
                                                    </template>
                                                </el-popconfirm>
                                            </template>
                                        </el-table-column>
                                    
                                    </el-table>
                                </div>
                            </div>
                            <div style="height: 30px;margin-top: 20px;" class="hr-flex-start">
								<el-pagination
									v-model:currentPage="pageNo"
									v-model:page-size="pageSize"
									:total="totalRows"
									:page-sizes="[10, 20, 50, 100]"
									small
									background
									@size-change="handleSizeChange"
									@current-change="handleCurrentChange"
									layout="total, sizes, prev, pager, next, jumper"
									class="w-h-100"
								/>
							</div>
                        </div>
                    </el-card>
                </div>
            </div>
        </div>
        <add-edit-check-type
            :repairInfo="repairInfo"
            :isUseDialog="isUseDialog"
            @updateData="getData"
            @cancelUseClick="cancelUseClick"
            @controlUseClick="controlUseClick"
        />
    </div>
</template>
<script lang="ts">
import { defineComponent, ref, onMounted , reactive , toRaw } from 'vue'
import getTableData from '/@/utils/getTableData'
// import { sysPosPage , sysPosDelete } from '/@/api/manage/manage.ts'
import AddEditCheckType from './component/add-edit-check-type.vue'
import useCurrentInstance from '/@/utils/hook/useCurrentInstance';
export default defineComponent( {
    name: 'check-type',
    components: { AddEditCheckType },
    setup(props){
        const { proxy } = useCurrentInstance();
        const $t = proxy.$t;
        
        const isUseDialog = ref() // 新增/编辑弹出框隐藏/显示
        const repairInfo = ref() // 传递子组件数据
        const searchVal = ref('1')
        const transferVal = ref() // 需要查询的值
        const projectNam = ref() // 人员名称数据
        const responsiblePle = ref() // 人员编号数据
        const recordPle = ref() // 工种名称数据
        const typePle = ref() // 人员类型数据
        const certificatePle = ref() // 发证机关数据
        const enableStatus = ref() // 是否启用
        let srcList:any = [] // 图片地址
        const searchObj = reactive({
            name : '',
            code : '',
        })

        /*** 截取日期格式方法 */
        const formatDate = (row:any, column:any) => {
          // 获取单元格数据
          let data = row[column.property]
          if(data == null) {
              return null
          }
          let dt = new Date(data)
          let month = (dt.getMonth() + 1) < 10 ? '0' + (dt.getMonth() + 1) : (dt.getMonth() + 1)
          let date = dt.getDate() < 10 ? '0' + dt.getDate() : dt.getDate()
          return dt.getFullYear() + '-' + month + '-' + date
        }

        /*** 搜索类型选择事件 searchChange */
        const searchChange = (val:any) => {
            console.log(val,'val')
            // transferVal.value = ''
        }

        /*** acquireChange 搜索下拉框选择的数据 ---- 传给接口数据 */
        const acquireChange = (val:any) => {
            console.log(val)
        }

        /*** searchClick 查询按钮 */
        const searchClick = () => {
            
        }

        /*** resetClick 重置按钮 */
        const resetClick = () => {
            searchObj.name = ''
            searchObj.code = ''
            searchVal.value = '1'
        }

        /*** nodeClick 新增/编辑点击事件 */
        const nodeClick = (val:string | object) => {
            val !== '' ? repairInfo.value = JSON.stringify(toRaw(val)) : repairInfo.value = ''
            isUseDialog.value = true
        }

        /*** deleteHandle 删除数据事件 */
        const deleteHandle = async (val: String | Number , updateFun: Function) => {
            console.log('删除事件')
            return
            let param = {id : val}
            try {
                // let res = await sysPosDelete(param)
                let res:any = {}
                if(res.success){
                    updateFun()
                }
            } catch (err) { return }
        }

        /*** cancelUseClick 取消事件 */
        const cancelUseClick = () => {
            isUseDialog.value = false
        }

        /*** controlUseClick 提交事件 */
        const controlUseClick = () => {
            isUseDialog.value = false
        }

        /*** lookImg 查看图片 */
        const lookImg = (val:any) => {
            srcList = []
            srcList.push(val.V_PersonnelImage)
        }

        return {
            ...getTableData(()=>{},{},searchObj),
            // ...getTableData(sysPosPage,{},searchObj),
            isUseDialog,
            cancelUseClick,
            controlUseClick,
            nodeClick,
            repairInfo,
            deleteHandle,
            resetClick,
            searchClick,

            searchOptions: [{
                value: '1',
                label: $t('k2Uv9N3Trufj48Sfbq8Ts')
            }, {
                value: '2',
                label: $t('vu8QCtd2iRBgRQjHltpUu')
            }, {
                value: '3',
                label: $t('hQmmlRmkje2IkDoxRZjj')
            }, {
                value: '4',
                label: $t('cJWTh3T27ke_4LpTw0Tr')
            }, {
                value: '5',
                label: $t('2yZtTmqrjIhTp6Xopiew')
            }, {
                value: '6',
                label: $t('4qSllUxIkPaA8Rqf3Jg8y')
            }], // 搜索方式
            searchVal,
            searchChange,
            transferVal,
            acquireChange,
            projectNam, // 人员名称数据
            responsiblePle, // 人员编号数据
            recordPle, // 工种名称数据
            typePle, // 人员类型数据
            certificatePle, // 发证机关数据
            enableStatus, // 是否启用
            lookImg,
        }
    },
} )
</script>
<style lang="scss"> @import '../style/public.scss'; </style>
<style scoped lang="scss">
    #check-type {
        .box-f{
            :deep(.el-form-item__label){
                padding: 0;
            }
        }
        :deep(.el-card__body) {
            height: 100%;
        }
        ul {

            list-style: none;

            li {
                cursor: pointer;

                &:hover {
                    color: red;
                }
            }
        }
        .icon-e{
            :deep(.el-icon){
                margin-right: 0px!important;
            }
        }
    }
</style>